package cn.com.cloudpioneer.evaluate.service;

import cn.com.cloudpioneer.evaluate.mapper.ResourceMapper;
import cn.com.cloudpioneer.evaluate.model.ResourceModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @auther maruikai
 * @create 2023/10/7-12:19
 */
@Service
public class ResourceService {

    @Resource
    private ResourceMapper resourceMapper;

    public void addResource(ResourceModel resourceModel) {
        int id = this.getId();
        resourceModel.setId(id);
        resourceMapper.addResource(resourceModel);
    }

    public List<ResourceModel> findByObjId(String objId) {
        return resourceMapper.findByObjId(objId);
    }

    public List<ResourceModel> findByObjIdAndPath(String objId, String filepath) {
        return resourceMapper.findByObjIdAndPath(objId, filepath);
    }

    public ResourceModel findById(long id) {
        return resourceMapper.findById(id);
    }

    public void delFile(long id) {
        resourceMapper.delFile(id);
    }

    private int getId() {
        int id = resourceMapper.getId();
        return id == 0 ? 1 : id + 1;
    }
}
